package com.market.controller;

import com.market.common.exception.ControllerException;
import com.market.common.vo.ResponseCode;
import com.market.common.vo.ResponseResult;
import com.market.entity.Sales;
import com.market.service.SalesService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sales")
public class SalesController {
    @Resource
    SalesService salesService;

    /**
     * 终端销售单查询
     * @return
     */
    @GetMapping("/select")
    public Sales select() {
        Sales sales = salesService.salesInquire();
        return sales;
    }

    /**
     * 终端销售单查询详细
     * @return
     * @throws ControllerException
     */
    @GetMapping("/salesDetailed")
    public ResponseResult<Sales> salesDetailed(Integer id) throws ControllerException {
        Sales salesDetailed = salesService.salesDetailed(id);
        return ResponseResult.success(ResponseCode.SUCCESS,salesDetailed);
    }

    /**
     * 终端退货单查询
     * @return
     */
    @GetMapping("/salesReturn")
    public ResponseResult<List<Sales>> salesReturn() throws ControllerException {
        List<Sales> sales = salesService.salesReturn();
        return ResponseResult.success(ResponseCode.SUCCESS,sales);
    }

    @GetMapping("returnDetailed")
    public ResponseResult<Sales> returnDetailed(Integer id) throws ControllerException {
        Sales sales = salesService.returnDetailed(id);
        return ResponseResult.success(ResponseCode.SUCCESS,sales);
    }

    /**
     * 终端销售单-编码查询
     * @param coding
     * @return
     * @throws ControllerException
     */
    @GetMapping("/selectCoding")
    public ResponseResult<Sales> selectCoding(String coding) throws ControllerException {
        Sales sales = salesService.selectCoding(coding);
        return ResponseResult.success(ResponseCode.SUCCESS,sales);
    }


    /**
     * 终端退货单-编码查询
     * @param coding
     * @return
     * @throws ControllerException
     */
    @GetMapping("/returnCoding")
    public ResponseResult<Sales> returnCoding(String coding) throws ControllerException {
        Sales sales = salesService.returnCoding(coding);
        return ResponseResult.success(ResponseCode.SUCCESS, sales);
    }
}
